package com.gitee.mars.tourserver.utils;

import com.gitee.mars.tourserver.constant.Constant;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wq
 * @version 1.0
 * @date 2021/04/14 13:32
 */
public class CityUtils {


    public static List<String> getCitysPinYin() throws BadHanyuPinyinOutputFormatCombination {
        String[] citys = Constant.citys;
        List<String> list = new ArrayList<>();
        for (String city : citys) {
            String province = city.split("市")[0];
            HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
            format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
            format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            String s = PinyinHelper.toHanYuPinyinString(province, format, "", true);
            list.add(s);
        }
        return list;
    }


}
